unit dlgUser;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  User;

type
  TfrmUser = class(TForm)
    btnAccept: TButton;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    edtUser: TEdit;
    edtPass: TEdit;
    chkEnabled: TCheckBox;
    btnCancel: TButton;
    procedure btnAcceptClick(Sender: TObject);
  private
    FAction: TUserAction;
    FUser: TUser;
    procedure FillForm;
  public
    class function Execute(AUser: TUser; AAction: TUserAction): Boolean;
  end;

implementation

{$R *.dfm}

{ TForm1 }

class function TfrmUser.Execute(AUser: TUser; AAction: TUserAction): Boolean;
begin
  with Create(nil) do
  begin
    Result := False;
    FAction := AAction;
    FUser := AUser;
    if AAction = acEdit then
      FillForm;
    if ShowModal = mrOk then
      Result := True;
    Free;
  end;
end;

procedure TfrmUser.btnAcceptClick(Sender: TObject);
begin
  with FUser do
  begin
    UserName := edtUser.Text;
    Password := edtPass.Text;
    Enabled := chkEnabled.Checked;
  end;
end;

procedure TfrmUser.FillForm;
begin
  edtUser.Text := FUser.UserName;
  edtPass.Text := FUser.Password;
  chkEnabled.Checked := FUser.Enabled;
end;

end.
 